<?php
#------------------------------------------------------------------------------------------
    function check_nonempty( $val ){
        $res = false;
        if ( trim($val) != '' )
            $res = true;
        return $res;
    }
#------------------------------------------------------------------------------------------
    function check_number( $val ){
       	$res = false;
       	if ( $val ){
       		if ( __check_integer($val) || __check_float($val) )
       		    $res = true;
       	}else{       		$res = true;
       	}
       return $res;
    }
#------------------------------------------------------------------------------------------
    function __check_integer( $val ){
       $res = false;
       $res = eregi( '^[0-9]+$', $val );
       return $res;
    }
#------------------------------------------------------------------------------------------
	function __check_float( $val ){
		$res = true;
		$buf = str_replace(',', '.', $val);
		$ext = explode('.', $buf);
		$index = sizeof( $ext );
		if ( ($index <= 2) && floatval($val) ){
			for($i=0; $i<$index; $i++){
				if ( !__check_integer( $ext[$i] ) ){
					$res = false;
					break;
				}
			}
		}else{			$res = false;
		}
		return $res;
	}
#------------------------------------------------------------------------------------------
    function check_alphastring( $val ){
       	$res = false;
       	if ( $val ){
       		$res = eregi( '^[a-zA-Z_ ]+$', $val );
       	}else{       		$res = true;
       	}
       return $res;
    }
#------------------------------------------------------------------------------------------
	function check_login( $val ){
       	$res = false;
       	if ( $val ){
      		 $res = eregi( '^[0-9a-zA-Z]+$', $val );
       	}else{       		$res = true;
       	}
       return $res;
	}
#------------------------------------------------------------------------------------------
    function check_email( $val ){
        $res = false;
        if ( $val ){
         	$mask =     '^([a-zA-Z0-9_]|-|.)+'.
            	        '@'.
                	    '([a-zA-Z0-9_]|-|.)+'.
                    	'[a-zA-Z]{2,4}$';
            $res = eregi( $mask, $val );
       	}else{       		$res = true;
       	}
        return $res;
    }
#------------------------------------------------------------------------------------------
    function check_ip( $val ){
	 	$res = true;
	 	if ( $val ){
	       	$buf = explode('.' , $val);
	       	if( sizeof($buf) == 4 ){
	         	for( $i=0; $i<4; $i++ ){
					if( !check_number( $buf[$i] ) || ( (int)$buf[$i] > 255) ){
						$res = false;
						break;
					}
	         	}
	       	}else{	       		$res = false;
	       	}
	 	}else{	 		$res = true;
	 	}
       	return $res;
    }
#------------------------------------------------------------------------------------------
	function check_date( $val ){
		$res = false;
		if ( $val ){
			$buf = explode('.', $val);
			$res = checkdate( intval($buf[1]), intval($buf[0]), intval($buf[2]) );
			unset($buf);
		}else{		    $res = true;
		}
		return $res;
	}
#------------------------------------------------------------------------------------------
	function check_time( $val ){
		$res = false;
		if ( $val ){
			$buf = explode(':', $val);
			$h = intval($buf[0]);
			$m = intval($buf[1]);
			if ( ( $h >= 0 ) && ( $h < 24 ) ){
				if ( ( $m >= 0 ) && ( $m < 60 ) )
				    $res = true;
			}
			unset($buf);
		}else{			$res = true;
		}
		return $res;
	}
#------------------------------------------------------------------------------------------
	function check_datetime( $val ){
		$res = false;
		if ( $val ){
			$buf = explode(' ', $val);
			if ( check_date($buf[0]) && check_time($buf[1]) )
			    $res = true;
			unset($buf);
		}else{			$res = true;
		}
		return $res;
	}
#------------------------------------------------------------------------------------------
?>
